$(function(){
    query();
})

function render(arr){
    let row=$('.rowData');
    let tb = $('#tbData');
    row.remove();
    arr.forEach(item => {
        let html=`
        <tr class="rowData" key="${itme.id}">
            <td>item.id</td>
            <td>item.name</td>
            <td>item.price</td>
            <td>
                <input type="button" value="编辑" onclick="Edit(${item.id})">
                <input type="button" value="删除" onclick="Del(${item.id})">
            </td>
        </tr>
        `
        tb.append(html)
    });
}

function query(){
    let keyword = $('#keyword').val()
    product(keyword).then(data=>{
        render(data)
    })
}

function Edit(id){
    location.href=`http://localhost:8000/${id}`
}

function add(){
    location.href=`http://localhost:8000/${id}`
}

function Del(id){
    let confirm =confirm(`确定删除id为${id}的数据吗？`)
    if(confirm){
        delProduct(id).then(data=>{
            let id = data.data.id
            $(`[key=${id}]`).remove()
        })
    }
}

